#include "GY_TapeCircular.h"
#include "Graphics/GY_GraphicsReflection.h"
#include <math.h>
#include <QtMath>
#include <QDebug>

GY_TapeCircular::GY_TapeCircular(const QString &guid, QGraphicsItem *parent)
    : GY_ContainerTransform(guid,this, parent)
{
    initializationPropertyInfo();
    this->setCenterPointF(m_PropertyInfoMap["Position"].propertyValue.toPointF());
    m_pClippingToolContainer = new GY_ClippingToolContainer(QString("%1_ClippingTool").arg(guid),this);
    m_pClippingToolContainer->setPos(QPointF(0,0));
    m_pRect = new QGraphicsRectItem(this);
    this->addToGroup(m_pClippingToolContainer);
    m_ChildrensMap.insert(m_pClippingToolContainer->getGuid(),m_pClippingToolContainer);
    m_pSimpleGroup = new GY_SimpleGroup(QString("%1_SimpleGroup").arg(guid),this);
    m_pClippingToolContainer->addItem((GY_Object*)m_pSimpleGroup);
    updateDraw();
}

GY_TapeCircular::~GY_TapeCircular()
{

}

void GY_TapeCircular::initializationPropertyInfo()
{
    GY_PropertyInfo ObjectName(this);
    ObjectName.propertyName = "ObjectName";
    ObjectName.propertyValue = QString();
    ObjectName.updateType = Update|OrdinaryAttributes;
    ObjectName.propertyType = QStringPropertyType;
    ObjectName.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateObjectName;
    m_PropertyInfoMap.insert("ObjectName",ObjectName);
    m_PropertyInfoMap[ObjectName.propertyName].setConnect();

    //位置
    GY_PropertyInfo positonPropertyInfo(this);
    positonPropertyInfo.propertyName="Position";
    positonPropertyInfo.propertyValue=QPointF(0,0);
    positonPropertyInfo.updateType = Update|MoveUpdate|PointOfRelative;
    positonPropertyInfo.propertyType = PointPropertyType;
    positonPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updatePosition;
    m_PropertyInfoMap.insert(positonPropertyInfo.propertyName,positonPropertyInfo);
    m_PropertyInfoMap[positonPropertyInfo.propertyName].setConnect();

    //是否显示
    GY_PropertyInfo isVisiblePropertyInfo(this);
    isVisiblePropertyInfo.propertyName="IsVisible";
    isVisiblePropertyInfo.propertyValue=true;
    isVisiblePropertyInfo.updateType = Update|OrdinaryAttributes;
    isVisiblePropertyInfo.propertyType = BoolPropertyType;
    isVisiblePropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateIsVisible;
    m_PropertyInfoMap.insert(isVisiblePropertyInfo.propertyName,isVisiblePropertyInfo);
    m_PropertyInfoMap[isVisiblePropertyInfo.propertyName].setConnect();

    //Value
    GY_PropertyInfo ValuePropertyInfo(this);
    ValuePropertyInfo.propertyName="Value";
    ValuePropertyInfo.propertyValue=0;
    ValuePropertyInfo.updateType = Update|OrdinaryAttributes;
    ValuePropertyInfo.propertyType = FloatPropertyType;
    ValuePropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateValue;
    m_PropertyInfoMap.insert(ValuePropertyInfo.propertyName,ValuePropertyInfo);
    m_PropertyInfoMap[ValuePropertyInfo.propertyName].setConnect();

    //ValuePerRevolution
    GY_PropertyInfo ValuePerRevolutionPropertyInfo(this);
    ValuePerRevolutionPropertyInfo.propertyName="ValuePerRevolution";
    ValuePerRevolutionPropertyInfo.propertyValue=1;
    ValuePerRevolutionPropertyInfo.updateType = Update|OrdinaryAttributes;
    ValuePerRevolutionPropertyInfo.propertyType = FloatPropertyType;
    ValuePerRevolutionPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateValuePerRevolution;
    m_PropertyInfoMap.insert(ValuePerRevolutionPropertyInfo.propertyName,ValuePerRevolutionPropertyInfo);
    m_PropertyInfoMap[ValuePerRevolutionPropertyInfo.propertyName].setConnect();

    //DisplayAreaLeft
    GY_PropertyInfo DisplayAreaLeftPropertyInfo(this);
    DisplayAreaLeftPropertyInfo.propertyName="DisplayArea.Left";
    DisplayAreaLeftPropertyInfo.propertyValue=-40;
    DisplayAreaLeftPropertyInfo.updateType = Update|OrdinaryAttributes;
    DisplayAreaLeftPropertyInfo.propertyType = FloatPropertyType;
    DisplayAreaLeftPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateDisplayAreaLeft;
    m_PropertyInfoMap.insert(DisplayAreaLeftPropertyInfo.propertyName,DisplayAreaLeftPropertyInfo);
    m_PropertyInfoMap[DisplayAreaLeftPropertyInfo.propertyName].setConnect();

    //DisplayAreaBottom
    GY_PropertyInfo DisplayAreaBottomPropertyInfo(this);
    DisplayAreaBottomPropertyInfo.propertyName="DisplayArea.Bottom";
    DisplayAreaBottomPropertyInfo.propertyValue=-20;
    DisplayAreaBottomPropertyInfo.updateType = Update|OrdinaryAttributes;
    DisplayAreaBottomPropertyInfo.propertyType = FloatPropertyType;
    DisplayAreaBottomPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateDisplayAreaBottom;
    m_PropertyInfoMap.insert(DisplayAreaBottomPropertyInfo.propertyName,DisplayAreaBottomPropertyInfo);
    m_PropertyInfoMap[DisplayAreaBottomPropertyInfo.propertyName].setConnect();

    //DisplayAreaRight
    GY_PropertyInfo DisplayAreaRightPropertyInfo(this);
    DisplayAreaRightPropertyInfo.propertyName="DisplayArea.Right";
    DisplayAreaRightPropertyInfo.propertyValue=40;
    DisplayAreaRightPropertyInfo.updateType = Update|OrdinaryAttributes;
    DisplayAreaRightPropertyInfo.propertyType = FloatPropertyType;
    DisplayAreaRightPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateDisplayAreaRight;
    m_PropertyInfoMap.insert(DisplayAreaRightPropertyInfo.propertyName,DisplayAreaRightPropertyInfo);
    m_PropertyInfoMap[DisplayAreaRightPropertyInfo.propertyName].setConnect();

    //DisplayAreaTop
    GY_PropertyInfo DisplayAreaTopPropertyInfo(this);
    DisplayAreaTopPropertyInfo.propertyName="DisplayArea.Top";
    DisplayAreaTopPropertyInfo.propertyValue=20;
    DisplayAreaTopPropertyInfo.updateType = Update|OrdinaryAttributes;
    DisplayAreaTopPropertyInfo.propertyType = FloatPropertyType;
    DisplayAreaTopPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateDisplayAreaTop;
    m_PropertyInfoMap.insert(DisplayAreaTopPropertyInfo.propertyName,DisplayAreaTopPropertyInfo);
    m_PropertyInfoMap[DisplayAreaTopPropertyInfo.propertyName].setConnect();

    //编辑点
    GY_PropertyInfo pointPropertyInfo(this);
    pointPropertyInfo.propertyName="Point";
    pointPropertyInfo.propertyValue=QPointF(200,0);
    pointPropertyInfo.updateType = NotUpdate;
    pointPropertyInfo.propertyType = PointPropertyType;
    pointPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updatePoint;
    m_PropertyInfoMap.insert(pointPropertyInfo.propertyName,pointPropertyInfo);
    m_PropertyInfoMap[pointPropertyInfo.propertyName].setConnect();

    //Motion位置
    GY_PropertyInfo MotionPropertyInfo(this);
    MotionPropertyInfo.propertyName="Motion";
    MotionPropertyInfo.propertyValue=QPointF(200,0);
    MotionPropertyInfo.updateType = Update|OrdinaryAttributes;
    MotionPropertyInfo.propertyType = PointPropertyType;
    MotionPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateMotion;
    m_PropertyInfoMap.insert(MotionPropertyInfo.propertyName,MotionPropertyInfo);
    m_PropertyInfoMap[MotionPropertyInfo.propertyName].setConnect();

    //左边距点
    GY_PropertyInfo leftPointPropertyInfo(this);
    leftPointPropertyInfo.propertyName="leftPoint";
    leftPointPropertyInfo.propertyValue=QPointF(-40,0);
    leftPointPropertyInfo.updateType = NotUpdate;
    leftPointPropertyInfo.propertyType = PointPropertyType;
    leftPointPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateLeftPoint;
    m_PropertyInfoMap.insert("leftPoint",leftPointPropertyInfo);
    m_PropertyInfoMap[leftPointPropertyInfo.propertyName].setConnect();

    //下边距点
    GY_PropertyInfo bottomPointPropertyInfo(this);
    bottomPointPropertyInfo.propertyName="bottomPoint";
    bottomPointPropertyInfo.propertyValue=QPointF(-20,0);
    bottomPointPropertyInfo.updateType = NotUpdate;
    bottomPointPropertyInfo.propertyType = PointPropertyType;
    bottomPointPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateBottomPoint;
    m_PropertyInfoMap.insert(bottomPointPropertyInfo.propertyName,bottomPointPropertyInfo);
    m_PropertyInfoMap[bottomPointPropertyInfo.propertyName].setConnect();

    //右边距点
    GY_PropertyInfo rightPointPropertyInfo(this);
    rightPointPropertyInfo.propertyName="rightPoint";
    rightPointPropertyInfo.propertyValue=QPointF(40,0);
    rightPointPropertyInfo.updateType = NotUpdate;
    rightPointPropertyInfo.propertyType = PointPropertyType;
    rightPointPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateRightPoint;
    m_PropertyInfoMap.insert(rightPointPropertyInfo.propertyName,rightPointPropertyInfo);
    m_PropertyInfoMap[rightPointPropertyInfo.propertyName].setConnect();

    //上边距点
    GY_PropertyInfo topPointPropertyInfo(this);
    topPointPropertyInfo.propertyName="topPoint";
    topPointPropertyInfo.propertyValue=QPointF(20,0);
    topPointPropertyInfo.updateType = NotUpdate;
    topPointPropertyInfo.propertyType = PointPropertyType;
    topPointPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_TapeCircular::updateTopPoint;
    m_PropertyInfoMap.insert(topPointPropertyInfo.propertyName,topPointPropertyInfo);
    m_PropertyInfoMap[topPointPropertyInfo.propertyName].setConnect();

}

void GY_TapeCircular::updateDraw()
{
    //!原版与复制版位置偏差
    QMap<GY_Object*,GY_Object*>::Iterator iter = m_copyItemMap.begin();
    while (iter != m_copyItemMap.end()) {
        //!获取位置属性计算偏差，updateProperty传入父类坐标位置
        if(iter.key()->inherits("GY_BasicsGraphicsObject"))
        {
            //不同情况不同处理方式
            if(iter.key()->getPropertyMap().contains("Position")) {
                //取出原图位置Position，加上偏移值Motion，再更新
                iter.value()->updateProperty("Position",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["Position"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

            }else if(iter.key()->getUserData(ClassType).toString() == "LinearTick") {

                iter.value()->updateProperty("StartPoint",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["StartPoint"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

                iter.value()->updateProperty("EndPoint",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["EndPoint"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

            }else if((iter.key()->getUserData(ClassType).toString() == "Rect") || (iter.key()->getUserData(ClassType).toString() == "Line") ||
                     (iter.key()->getUserData(ClassType).toString() == "Fillet")) {

                iter.value()->updateProperty("Point1",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["Point1"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

                iter.value()->updateProperty("Point2",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["Point2"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

            }else if((iter.key()->getUserData(ClassType).toString() == "PolygonItem") || (iter.key()->getUserData(ClassType).toString() == "PolylineItem")) {
                for(int i=0;i<iter.key()->getPropertyMap()["PtsArray.Size"].propertyValue.toInt();i++) {

                    iter.value()->updateProperty(QString("PtsArray[%1]").arg(i),((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()[QString("PtsArray[%1]").arg(i)].propertyValue.toPointF())
                            +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

                }
            }else if(iter.key()->getUserData(ClassType).toString() == "Bezier") {

                iter.value()->updateProperty("Point1",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["Point1"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

                iter.value()->updateProperty("Point2",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["Point2"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

                iter.value()->updateProperty("Ctrl1",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["Ctrl1"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

                iter.value()->updateProperty("Ctrl2",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["Ctrl2"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));

            }else {

                iter.value()->updateProperty("Center",((GY_BasicsGraphicsObject *)iter.key())->mapToParent(iter.key()->getPropertyMap()["Center"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));
            }
        }
        else if(iter.key()->inherits("GY_ContainerTransform"))
        {
            if(iter.key()->getPropertyMap().contains("Position")) {
                iter.value()->updateProperty("Position",((GY_ContainerTransform *)iter.key())->mapToParent(iter.key()->getPropertyMap()["Position"].propertyValue.toPointF())
                        +QPointF(-m_PropertyInfoMap["Motion"].propertyValue.toPointF().x(),-m_PropertyInfoMap["Motion"].propertyValue.toPointF().y()));
            }
        }
        ++iter;
    }

    qreal left = m_PropertyInfoMap["DisplayArea.Left"].propertyValue.toReal();
    qreal bottom = m_PropertyInfoMap["DisplayArea.Bottom"].propertyValue.toReal();
    qreal right = m_PropertyInfoMap["DisplayArea.Right"].propertyValue.toReal();
    qreal top = m_PropertyInfoMap["DisplayArea.Top"].propertyValue.toReal();
    qreal width = abs(right - left);
    qreal height = abs(top - bottom);

    //!根据上面值画出所有编辑点
    m_PropertyInfoMap["leftPoint"].propertyValue = QPointF(left,(top+bottom)/2);
    m_PropertyInfoMap["rightPoint"].propertyValue = QPointF(right,(top+bottom)/2);
    m_PropertyInfoMap["topPoint"].propertyValue = QPointF((right+left)/2,top);
    m_PropertyInfoMap["bottomPoint"].propertyValue = QPointF((right+left)/2,bottom);

    //!设置编辑点
    QMap<QVariant,QPointF> editPoints = {{"Point",m_PropertyInfoMap["Motion"].propertyValue.toPointF()},
                                         {"leftPoint",m_PropertyInfoMap["leftPoint"].propertyValue.toPointF()},
                                         {"rightPoint",m_PropertyInfoMap["rightPoint"].propertyValue.toPointF()},
                                         {"topPoint",m_PropertyInfoMap["topPoint"].propertyValue.toPointF()},
                                         {"bottomPoint",m_PropertyInfoMap["bottomPoint"].propertyValue.toPointF()}
                                        };
    this->setEditPointF(editPoints);

    //!控制属性value绘图
    QPointF motion = m_PropertyInfoMap["Motion"].propertyValue.toPointF();
    float valuePerRevolution = m_PropertyInfoMap["ValuePerRevolution"].propertyValue.toReal();
    float value = m_PropertyInfoMap["Value"].propertyValue.toReal();
    //余数
    float remainderNumber = fmod(abs(value), valuePerRevolution);
    if((valuePerRevolution == 0) || (remainderNumber == 0)) {
        //valuePerRevolution为0，不进行移动 ,余数0

    }else {
        //比例大于0.5,向Motion点正方向移动，小于等于反方向移动
        float propertion = remainderNumber/valuePerRevolution;
        if(propertion <= 0.5) {
            m_pSimpleGroup->setPos((-motion*propertion));
        }else {
            m_pSimpleGroup->setPos(((1-propertion)*motion));
        }
    }

    //!剪切工具剪切
    QPainterPath path;
    QRectF rect = QRectF((left<right)?left:right,(bottom<top)?bottom:top, width, height);
    path.addRect(rect);
    this->removeFromGroup(m_pRect);
    m_pRect->setRect(rect);
    this->addToGroup(m_pRect);
    m_pClippingToolContainer->setIsCut(true);
    m_pClippingToolContainer->setShape(path);
}

bool GY_TapeCircular::addItem(GY_Object *pItem)
{
    //!移动容器回到原点
    m_pSimpleGroup->setPos(QPointF(0,0));
    GY_Object *copyItem = pItem->copyItem();
    //原版层级高
    if(pItem->inherits("GY_BasicsGraphicsObject"))
    {
        ((GY_BasicsGraphicsObject *)pItem)->setZValue(99+m_ZValue);
        ((GY_BasicsGraphicsObject *)copyItem)->setZValue(m_ZValue);
    }
    else if(pItem->inherits("GY_ContainerTransform"))
    {
        if(QString(((GY_ContainerTransform *)pItem)->metaObject()->className()) == "GY_RepeatGroup") {
            ((GY_RepeatGroup *)copyItem)->setName();
            copyItem->setObjName(copyItem->getObjName()+"___0");
        }
//        qDebug()<<((GY_ContainerTransform *)pItem)->getChildrensMap().keys().size()<<
//                  ((GY_ContainerTransform *)pItem)->metaObject()->className()<<"size-------------------";
        ((GY_ContainerTransform *)pItem)->setZValue(99+m_ZValue);
        ((GY_ContainerTransform *)copyItem)->setZValue(m_ZValue);
    }
    m_ZValue++;
    //添加原版
    m_pSimpleGroup->addItem(pItem);
    //拷贝用原版，不拷复制品
    m_orderChildrensMap.push_back(pItem);
    //添加复制版
    m_pSimpleGroup->addItem(copyItem);
    m_copyItemMap.insert(pItem,copyItem);

    //!原版属性和复制版属性关联
    connect((GY_Object*)pItem,&GY_Object::updatePropertyEvent,this,&GY_TapeCircular::updateCopyItemProperty);

    updateDraw();
    return true;
}

bool GY_TapeCircular::removItem(const QString &guid)
{
    return m_pSimpleGroup->removItem(guid);
}

bool GY_TapeCircular::removItem(const GY_Object *pItem)
{
    //移除原版
    bool remove = m_pSimpleGroup->removItem((GY_Object*)pItem);
    m_pClippingToolContainer->removItem((GY_Object*)pItem);
    this->GY_ContainerTransform::removItem((GY_Object*)pItem);
    //删除复制版
    m_copyItemMap[(GY_Object*)pItem]->deleteLater();
    m_copyItemMap[(GY_Object*)pItem] = nullptr;
    m_copyItemMap.remove((GY_Object*)pItem);
    //取消关联
    disconnect((GY_Object*)pItem,0,this,0);
    updateDraw();
    return remove;
}

GY_Object *GY_TapeCircular::copyItem(const QString &guid)
{
    if(getUserData(GY_ENUM::IsCopy) == 1) {
        GY_Object *tmp;
        this->copyItemSig(&tmp);
        //更新copyItem属性列表
        QMap<QString,GY_PropertyInfo>::Iterator iterProperty = m_PropertyInfoMap.begin();
        while (iterProperty != m_PropertyInfoMap.end()) {
            if(((iterProperty.value().updateType)&PointOfRelative) == PointOfRelative) {
                tmp->updateProperty(iterProperty.key(), submittingPropertyValues(iterProperty.value().updateType,iterProperty.value().propertyValue,this));
            }else if(((iterProperty.value().updateType)&NotUpdate) == NotUpdate){
                ++iterProperty;
                continue;
            }else {
                tmp->updateProperty(iterProperty.key(), iterProperty.value().propertyValue);
            }
            ++iterProperty;
        }
        return tmp;
    }
    GY_Object* pObj;
    if(guid.isEmpty()) {
        pObj = (GY_Object*)GY_GraphicsReflection::getInstance()->newInstanceObjectClass(this->metaObject()->className(),this->getGuid()+"-"+QString::number(m_MyGuid));
        m_MyGuid++;
    }else {
        pObj = (GY_Object*)GY_GraphicsReflection::getInstance()->newInstanceObjectClass(this->metaObject()->className(),guid);
    }
    if(pObj == nullptr) {
        qDebug()<<this->getGuid()<<"isEmpty";
        return nullptr;
    }
    QVector<GY_Object *> childrens = m_orderChildrensMap;
    for(int i=0;i<childrens.size();i++) {
        ((GY_ContainerTransform*)pObj)->addItem(childrens[i]->copyItem());
    }

    QMap<QString,GY_PropertyInfo>::Iterator iterProperty = m_PropertyInfoMap.begin();
    while (iterProperty != m_PropertyInfoMap.end()) {
        if(((iterProperty.value().updateType)&PointOfRelative) == PointOfRelative) {
            pObj->updateProperty(iterProperty.key(), submittingPropertyValues(iterProperty.value().updateType,iterProperty.value().propertyValue,this));
        }else if(((iterProperty.value().updateType)&NotUpdate) == NotUpdate){
            ++iterProperty;
            continue;
        }else {
            pObj->updateProperty(iterProperty.key(), iterProperty.value().propertyValue);
        }
        ++iterProperty;
    }
    connect(pObj,&GY_Object::copyItemSig,this,&GY_Object::originalVersion);
    pObj->setUserData(GY_ENUM::IsCopy, QVariant::fromValue(1));
    return pObj;
}

void GY_TapeCircular::updateCopyItemProperty(const GY_Object *pObject, const QString &propertyName, const QVariant &propertyValue, const PropertyType &)
{
//    qDebug()<<pObject->getObjName()<<propertyName<<propertyValue;
    if(propertyName == "ObjectName") {
        return;
    }
    m_copyItemMap[(GY_Object*)pObject]->updateProperty(propertyName,propertyValue);
}

bool GY_TapeCircular::updatePosition(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    //setpos设置为父级坐标
    QPointF point = value.toPointF();
    if(this->parentItem()) {
        point = this->mapToParent(this->mapFromScene(value.toPointF()));
    }
    this->setPos(point);
    m_PropertyInfoMap[name].propertyValue=this->mapFromScene(value.toPointF());
    return true;
}

bool GY_TapeCircular::updateIsVisible(const QString &name, const QVariant &value)
{
    if(!value.canConvert<bool>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value.toBool();
    this->setVisible(value.toBool());
    return true;
}

bool GY_TapeCircular::updateValue(const QString &name, const QVariant &value)
{
    if(!value.canConvert<float>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;

    for(const auto& key : m_copyItemMap.keys()) {
        GY_Object *copyItem1 = key->copyItem();
        //原版层级高
        if(key->inherits("GY_BasicsGraphicsObject"))
        {
            ((GY_BasicsGraphicsObject *)key)->setZValue(99+m_ZValue);
            ((GY_BasicsGraphicsObject *)copyItem1)->setZValue(m_ZValue);
        }
        else if(key->inherits("GY_ContainerTransform"))
        {
            if(QString(((GY_ContainerTransform *)key)->metaObject()->className()) == "GY_RepeatGroup") {
                ((GY_RepeatGroup *)copyItem1)->setName();
                copyItem1->setObjName(copyItem1->getObjName()+"___0");
            }
            ((GY_ContainerTransform *)key)->setZValue(99+m_ZValue);
            ((GY_ContainerTransform *)copyItem1)->setZValue(m_ZValue);
        }
        m_ZValue++;
        //添加原版
        m_pSimpleGroup->addItem(key);
        //拷贝用原版，不拷复制品
        m_orderChildrensMap.push_back(key);
        //添加复制版
        m_pSimpleGroup->addItem(copyItem1);
        m_copyItemMap.insert(key,copyItem1);

        //!原版属性和复制版属性关联
        connect((GY_Object*)key,&GY_Object::updatePropertyEvent,this,&GY_TapeCircular::updateCopyItemProperty);
    }

    updateDraw();
    return true;
}

bool GY_TapeCircular::updateValuePerRevolution(const QString &name, const QVariant &value)
{
    if(!value.canConvert<float>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
    updateDraw();
    return true;
}

bool GY_TapeCircular::updateDisplayAreaLeft(const QString &name, const QVariant &value)
{
    if(!value.canConvert<float>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
    updateDraw();
    return true;
}

bool GY_TapeCircular::updateDisplayAreaBottom(const QString &name, const QVariant &value)
{
    if(!value.canConvert<float>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
    updateDraw();
    return true;
}

bool GY_TapeCircular::updateDisplayAreaRight(const QString &name, const QVariant &value)
{
    if(!value.canConvert<float>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
    updateDraw();
    return true;
}

bool GY_TapeCircular::updateDisplayAreaTop(const QString &name, const QVariant &value)
{
    if(!value.canConvert<float>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
    updateDraw();
    return true;
}

bool GY_TapeCircular::updatePoint(const QString &, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    m_PropertyInfoMap["Motion"].propertyValue = this->mapFromScene(value.toPointF());
    updateDraw();
    return true;
}

bool GY_TapeCircular::updateMotion(const QString &, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    m_PropertyInfoMap["Motion"].propertyValue = value.toPointF();
    updateDraw();
    return true;
}

bool GY_TapeCircular::updateLeftPoint(const QString &, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    QPointF leftPoint = this->mapFromScene(value.toPointF());
    m_PropertyInfoMap["DisplayArea.Left"].propertyValue = leftPoint.x()-m_PropertyInfoMap["Position"].propertyValue.toPointF().x();
    updateDraw();
    return true;
}

bool GY_TapeCircular::updateBottomPoint(const QString &, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    QPointF bottomPoint = this->mapFromScene(value.toPointF());
    m_PropertyInfoMap["DisplayArea.Bottom"].propertyValue = bottomPoint.y()-m_PropertyInfoMap["Position"].propertyValue.toPointF().y();
    updateDraw();
    return true;
}

bool GY_TapeCircular::updateRightPoint(const QString &, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    QPointF rightPoint = this->mapFromScene(value.toPointF());
    m_PropertyInfoMap["DisplayArea.Right"].propertyValue = rightPoint.x()-m_PropertyInfoMap["Position"].propertyValue.toPointF().x();
    updateDraw();
    return true;
}

bool GY_TapeCircular::updateTopPoint(const QString &, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    QPointF topPoint = this->mapFromScene(value.toPointF());
    m_PropertyInfoMap["DisplayArea.Top"].propertyValue = topPoint.y()-m_PropertyInfoMap["Position"].propertyValue.toPointF().y();
    updateDraw();
    return true;
}




